<?php
/**
 * Created by PhpStorm.
 * User: 田家强
 * Date: 2017/4/3
 * Time: 14:10
 */

namespace Home\Controller;



use Think\Controller;

class ResController extends Controller
{

 public function index()
 {
     $headConf = ['title'=>'维依尚品_注册页面','js'=>['list']];
     $this->assign('headConf',$headConf);

     if (IS_POST){
//			dd($_POST);die;
         //检测账号是否已经注册
         $userData=$_POST;
         $dbData=m('login')->select();
         foreach ($dbData as $k=>$v){
             if ($v['username'] == $userData['username']){
                 $this->error('这个账号已经注册,换一个吧!');exit;
             }
         }
         if (!(new \Think\Verify())->check($userData['code'])){
             $this->error('验证码错误');exit;
         }
         $userData['password']=md5($userData['password']);
         m('login')->add($userData);
         $this->success('注册成功',u('home/login/index'));exit;
     }
     cookie('oldControllerName',CONTROLLER_NAME);
     $this->display();
 }

    /**
     * 验证码设置方法
     */
    public function code()
    {
        //验证码设置
        $config =    array(
            'fontSize'    =>    30,    // 验证码字体大小
            'length'      =>    3,     // 验证码位数
            'useNoise'    =>    false, // 关闭验证码杂点
            'imageH'      =>    70,     //验证码高度设置
        );
        //显示验证码 【设置验证码时要传参（$config）】
        $Verify = new \Think\Verify($config);
        $Verify->entry();
    }

    // 检测输入的验证码是否正确，$code为用户输入的验证码字符串【在上面调用该方法】
    public function check_verify($code, $id = '')
    {
        $verify = new \Think\Verify();
        return $verify->check($code, $id);
    }

}